A truckload of minor changes to improve error reporting from Garmin modules.
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Mon, 9 Jan 2006 22:47:08 +0000 (22:47 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Mon, 9 Jan 2006 22:47:08 +0000 (22:47 +0000)
gpsbabel/jeeps/gpsserial.c
gpsbabel/jeeps/gpsserial.h
gpsbabel/jeeps/gpsusbwin.c
gpsbabel/jeeps/gpsutil.c
gpsbabel/jeeps/gpsutil.h

index 918423adec157742249ccb878f824024cf3b2283..27b8b6a22de12a1a859ccfff01b5eb3b175f6a5b 100644 (file)
@@ -67,18 +67,22 @@ static HANDLE comport;
 /*
  * Display an error from the serial subsystem.
  */
-void GPS_Serial_Error(char *hdr)
+void GPS_Serial_Error(char *mb, ...)
 {
+       va_list ap;
        char msg[200];
        char *s;
+       int b;
 
-       strcpy(msg, hdr);
-       s = msg + strlen(hdr);
+       va_start(ap, mb);
+//     strcpy(msg, msg);
+       b = vsnprintf(msg, sizeof(msg), mb, ap);
+       s = msg + b;
        *s++ = ':';
        *s++ = ' ';
 
        FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, 0, 
-                       GetLastError(), 0, s, sizeof(msg) - strlen(hdr) - 2, 0 );
+                       GetLastError(), 0, s, sizeof(msg) - b - 2, 0 );
        GPS_Error(msg);
 }
 
@@ -99,7 +103,7 @@ int32 GPS_Serial_On(const char *port, int32 *fd)
                                          OPEN_EXISTING, 0, NULL);
 
        if (comport == INVALID_HANDLE_VALUE) {
-               GPS_Serial_Error("CreateFile");
+               GPS_Serial_Error("CreateFile on '%s' failed", port);
                gps_errno = SERIAL_ERROR;
                return 0;
        }
@@ -125,7 +129,7 @@ int32 GPS_Serial_On(const char *port, int32 *fd)
        tio.StopBits = ONESTOPBIT;
 
        if (!SetCommState (comport, &tio)) {
-               GPS_Serial_Error("SetCommState");
+               GPS_Serial_Error("SetCommState on port '%s' failed", port);
                CloseHandle(comport);
                comport = INVALID_HANDLE_VALUE;
                gps_errno = SERIAL_ERROR;
@@ -259,7 +263,7 @@ int32 GPS_Serial_Savetty(const char *port)
     {
        perror("open");
        gps_errno = SERIAL_ERROR;
-       GPS_Error("SERIAL: Cannot open serial port");
+       GPS_Error("SERIAL: Cannot open serial port '%s'", port);
        return 0;
     }
     
@@ -301,7 +305,7 @@ int32 GPS_Serial_Restoretty(const char *port)
     {
        perror("open");
        gps_errno = HARDWARE_ERROR;
-       GPS_Error("SERIAL: Cannot open serial port");
+       GPS_Error("SERIAL: Cannot open serial port '%s'", port);
        return 0;
     }
     
@@ -341,7 +345,7 @@ int32 GPS_Serial_Open(int32 *fd, const char *port)
     if((*fd = open(port, O_RDWR))==-1)
     {
        perror("open");
-       GPS_Error("SERIAL: Cannot open serial port");
+       GPS_Error("SERIAL: Cannot open serial port '%s'", port);
        gps_errno = SERIAL_ERROR;
        return 0;
     }
@@ -545,14 +549,14 @@ int32 GPS_Serial_On(const char *port, int32 *fd)
     }
     if(!GPS_Serial_Savetty(port))
     {
-       GPS_Error("Cannot access serial port");
+       GPS_Error("Cannot access serial port '%s'", port);
        gps_errno = SERIAL_ERROR;
        return 0;
     }
     
     if(!GPS_Serial_Open(fd,port))
     {
-       GPS_Error("Cannot open serial port");
+       GPS_Error("Cannot open serial port '%s'", port);
        gps_errno = SERIAL_ERROR;
        return 0;
     }
@@ -669,14 +673,14 @@ int32 GPS_Serial_On_NMEA(const char *port, int32 *fd)
 
     if(!GPS_Serial_Savetty(port))
     {
-       GPS_Error("Cannot access serial port");
+       GPS_Error("Cannot access serial port '%s'", port);
        gps_errno = SERIAL_ERROR;
        return 0;
     }
     
     if(!GPS_Serial_Open_NMEA(fd,port))
     {
-       GPS_Error("Cannot open serial port");
+       GPS_Error("Cannot open serial port '%s'", port);
        gps_errno = SERIAL_ERROR;
        return 0;
     }
index 7d3958d4846424e4463fabeae5afcea90bcad636..7726bfbbcb63d403150d89595c3cf5510d2087a8 100644 (file)
@@ -24,7 +24,7 @@ int32  GPS_Serial_Flush(int32 fd);
 int32  GPS_Serial_On_NMEA(const char *port, int32 *fd);
 int32  GPS_Serial_Read(int32 ignored, void *ibuf, int size);
 int32  GPS_Serial_Write(int32 ignored, const void *obuf, int size);
-void   GPS_Serial_Error(char *hdr);
+void   GPS_Serial_Error(char *hdr, ...);
 
 
 #endif
index 7362caf9c382fdfdc028f28e1283941713e91c86..0cd33b1086e415e1c7fb0993c3f08f39ef40d7b5 100644 (file)
@@ -88,6 +88,7 @@ gusb_open(const char *pname)
 
        if (hdevinfo == INVALID_HANDLE_VALUE) {
                GPS_Serial_Error("SetupDiGetClassDevs failed");
+               warning("Is the Garmin driver installed?");
                return 0;
        }
 
@@ -118,7 +119,7 @@ gusb_open(const char *pname)
        usb_handle = CreateFile(pdd->DevicePath, GENERIC_READ|GENERIC_WRITE, 
                        0, NULL, OPEN_EXISTING, 0, NULL );
        if (usb_handle == INVALID_HANDLE_VALUE) {
-               GPS_Serial_Error("CreateFile failed");
+               GPS_Serial_Error("CreateFile on '%' failed", pdd->DevicePath);
                return 0;
        }
 
index 7311d019a638e052f4df63ec2d20c4538758da5e..b5cf4b7a62455aa9159c6f2b598ecfaaa51a5f02 100644 (file)
@@ -499,14 +499,20 @@ void GPS_Fatal(char *s)
 ** @@
 ****************************************************************************/
 
-void GPS_Error(char *s)
+void GPS_Error(char *fmt, ...)
 {
+    va_list argp;
+    va_start(argp, fmt);
+
     if(!gps_error)
        return;
 
-    fprintf(stderr,"[ERROR] %s\n",s);
-    fflush(stderr);
 
+    fprintf(stderr, "[ERROR] ");
+    vfprintf(stderr, fmt, argp);
+    fprintf(stderr, "\n");
+
+    va_end(argp);
     return;
 }
 
index 30027885c45a8c7d25dc2c28e4427d84d51df1dc..adb75b961ab8756c3221f01b64b67a092fa0ae3d 100644 (file)
@@ -25,7 +25,7 @@ void   GPS_Util_Put_Uint(UC *s, const uint32 v);
 uint32 GPS_Util_Get_Uint(const UC *s);
 
 void   GPS_Warning(char *s);
-void   GPS_Error(char *s);
+void   GPS_Error(char *fmt, ...);
 void   GPS_Fatal(char *s);
 void   GPS_Enable_Error(void);
 void   GPS_Enable_Warning(void);